﻿using System;

class BinaryToHexadecimal
{
    static void Main()
    {
        //Exercise 6.
        //Write a program to convert binary numbers to hexadecimal numbers (directly).

        //For example: 11111110 -> FE;  000111110100 -> 1F4

        Console.Write("Enter a binary number: ");
        string numberBinary = Console.ReadLine();        
        string numberHex = "";        

        for (int i = 0; i < numberBinary.Length; i = i + 4)
        {
            switch (numberBinary.Substring(i, 4))
            {
                case "0000":
                    numberHex += "0";
                    break;
                case "0001":
                    numberHex += "1";
                    break;
                case "0010":
                    numberHex += "2";
                    break;
                case "0011":
                    numberHex += "3";
                    break;
                case "0100":
                    numberHex += "4";
                    break;
                case "0101":
                    numberHex += "5";
                    break;
                case "0110":
                    numberHex += "6";
                    break;
                case "0111":
                    numberHex += "7";
                    break;
                case "1000":
                    numberHex += "8";
                    break;
                case "1001":
                    numberHex += "9";
                    break;
                case "1010":
                    numberHex += "A";
                    break;
                case "1011":
                    numberHex += "B";
                    break;
                case "1100":
                    numberHex += "C";
                    break;
                case "1101":
                    numberHex += "D";
                    break;
                case "1110":
                    numberHex += "E";
                    break;
                case "1111":
                    numberHex += "F";
                    break;
                default:
                    numberHex += "";
                    break;
            }
        }
        Console.WriteLine(numberHex);
    }
}

